#pragma once

#include <jtag/tapc.h>
#include "adapter.h"

class bitbang : public tapc, public openocd::adapter
{
public:
    typedef enum
    {
        BB_LOW = 0,
        BB_HIGH = 1,
        BB_ERROR
    } bb_value_t;

public:
    bitbang();

private:
    virtual int execute_queue(struct list_head *chead);

private:
    virtual void bb_reset(int trst, int srst);
    virtual void bb_blink(int on);

    virtual int bb_read();

    virtual int bb_write(int tck, int tms, int tdi);
    /* for remote bitbang only */
    virtual int bb_sample();
    virtual int bb_read_sample();
    virtual void bb_flush();

private:
    int execute(struct jtag_command *cmd);
    int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, unsigned scan_size);
    void bitbang_end_state(tap_state_t state);
    int bitbang_state_move(int skip);
    int bitbang_runtest(int num_cycles);
    int bitbang_path_move(struct pathmove_command *cmd);
    int bitbang_stableclocks(int num_cycles);
    int bitbang_execute_tms(struct jtag_command *cmd);
    int bitbang_execute_reset(struct jtag_command *cmd);

protected:
    int buf_size; //recv bufsz, for remote bitbang
};
